package com.itheima.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.log.mapper.LogMapper;
import com.itheima.log.service.LogService;
import com.itheima.model.common.dtos.ResponseResult;
import com.itheima.model.common.dtos.TradeDto;
import com.itheima.model.common.pojos.Trade;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class LogServiceImpl extends ServiceImpl<LogMapper, Trade> implements LogService {

    private final LogMapper logMapper;

    @Override
    public ResponseResult list(TradeDto tradeDto) {
        // 1.创建查询条件
        LambdaQueryWrapper<Trade> wrapper = new LambdaQueryWrapper<>();
        if (tradeDto.getUid() != null){
            wrapper.eq(Trade::getAid, tradeDto.getUid());
        }
        if (tradeDto.getTradeDate() != null){
            wrapper.eq(Trade::getTradeTime, tradeDto.getTradeDate());
        }
        // 2.到数据库中查询数据
        List<Trade> trades = logMapper.selectList(wrapper);
        // 3.封装返回结果并返回
        return ResponseResult.okResult(trades);
    }
}
